<?php

class DefaultController extends BackendController
{
    public $active = "pluginslist";

	public function actionIndex()
	{
	    $module = Yii::app()->getModule("plugins");
        $controllerPath = $module->getControllerPath();
        $controllers = scandir($controllerPath);
        $controllerList = array();
        foreach ($controllers as $controller){
            if($controller!="."&&$controller!='..'&&$controller!='DefaultController.php'){
                $controllerList[] = str_replace(".php","",$controller);
            }
        }

        $plugins = array();
        foreach ($controllerList as $item){
            $create = Yii::createComponent('plugins.controllers.'.$item,array(
                'actionID'=>$item
            ));
            $plugins[] = array(
                'id'=>$create->active,
                'title'=>$create->plug_title,
                'version'=>$create->plug_version,
                'description'=>$create->plug_description,
                'controller'=>$create->plug_controller
            );
        }
        $this->data['plugins'] = $plugins;

        $installedList = $this->connection->createCommand("select * from rk_plug ")->queryAll();
        $installed = array();
        foreach ($installedList as $item){
            $installed[$item['plug_key']] = $item;
        }
        $this->data['installed'] = $installed;

		$this->render('index',$this->data);
	}
}